import path from 'path';
import fs from 'fs';
import {fileURLToPath, pathToFileURL} from 'url';
import {dirname} from 'path';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
//文件路径
const associate = (dir) => {
  const files = fs.readdirSync(dir);
  files.forEach(file => {
    let filePath = path.resolve(dir, file);
    const stats = fs.statSync(filePath);
    if (stats.isDirectory()) {
      associate(filePath);
    } else {
      filePath = pathToFileURL(filePath);
      import(filePath);
      // require(filePath);
    }
  })
}
associate(__dirname);

